# == Schema Information
#
# Table name: promotions
#
#  id          :integer          not null, primary key
#  title       :string
#  type        :string
#  actived     :boolean
#  started_at  :datetime
#  ended_at    :datetime
#  discount    :decimal(, )
#  created_at  :datetime         not null
#  updated_at  :datetime         not null
#  product_ids :string           default([]), is an Array
#  desc        :text
#  summary     :string
#

class Promotion < ApplicationRecord

  validates :title, presence: { message: '活动名不能为空' }
  validates :started_at, presence: { message: '开始时间不能为空' }
  validates :ended_at, presence: { message: '结束时间不能为空' }
  validates :discount, presence: { message: '折扣不能为空' }
  validates :desc, presence: { message: '活动描述不能为空' }

  before_create :set_actived

  private

  def set_actived
    self.actived = true
  end

end
